//
//  ModelSingle.m
//  RadioUrl
//
//  Created by ios on 16/4/22.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ModelSingleton.h"
#import "RadioModel.h"
#import <AFNetworking.h>
#import "NetWorking.h"
@interface ModelSingleton ()

@property (nonatomic,strong)NSMutableArray *mArr;

@end
@implementation ModelSingleton
static ModelSingleton *modelSingleton;

- (NSMutableArray *)mArr
{
    if (!_mArr) {
        _mArr = [NSMutableArray array];
    }
    return  _mArr;
}

+(ModelSingleton *)shareModelSingleton{
    static dispatch_once_t oneToken;
    dispatch_once(&oneToken, ^{
        modelSingleton = [[ModelSingleton alloc]init];
    });
    return modelSingleton;
}


//根据soundIDs获取当前电台歌曲模型数组
-(void)radioModelListWithSoundIDs:(NSString *)soundIDs successList:(void(^)(NSMutableArray *radioList))successList{
    NSArray *radioSoundIDs = [soundIDs componentsSeparatedByString:@","];
    
  NSMutableArray * temp  = [NSMutableArray array];
    for (NSString *soundID in radioSoundIDs) {
        
//        NSString *radioSource = [NSString stringWithFormat:@"http://www.ximalaya.com/tracks/%@.json",soundID];
        __weak ModelSingleton *weakSelf = self;
       
       
        [NetWorking searchWithJsonUrl:soundID success:^(RadioModel *radioModel) {
            
//            NSLog(@"***********%@---/n%@+++++++++++",radioModel.radioPath,radioModel.radioImage);
            [temp addObject:radioModel];
            if (temp.count == radioSoundIDs.count) {
                weakSelf.radioModelList = temp;
//                [temp removeAllObjects];
                successList(temp);
                NSLog(@"%lu &&&&&&&&&&&&&&%lu",(unsigned long)temp.count,(unsigned long)radioSoundIDs.count);
                NSLog(@"----------------------100fen");
            }
            
            [self.mArr addObject:radioModel];
        } failure:^(NSError *error) {
            NSLog(@"%@",error);
        } ];
     }
//    NSLog(@"----%@",self.radioModelList);
    
}


@end
